﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace IMIS_ERP.Web.Order_Info
{
    public partial class Factory_Products_Me : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind_GV("2010-1-1", "2110-1-1");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Bind_GV(txthTime1.Text.Trim() + " 00:00:00", txthTime2.Text.Trim() + " 23:59:59");
        }

        /// <summary>为GridView绑定数据
        /// 	<remark>2011-03-23 BY 河北大学信管团队</remark>
        /// </summary>
        private void Bind_GV(string strTime1, string strTime2)
        {
            IMIS_ERP.BLL.Order_Products bll = new IMIS_ERP.BLL.Order_Products();
            SqlDataReader dr = bll.GetProducts_Factory(Session["fiID"].ToString(), strTime1, strTime2);
            DataTable dt = new DataTable();
            dt.Columns.Add("opPcID");
            dt.Columns.Add("NumSum");
            dt.Columns.Add("MachineFeeSum");
            dt.Columns.Add("AreaSum");
            dt.Columns.Add("WeightSum");
            decimal sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    dt.Rows.Add(dr["opPcID"].ToString(), dr["NumSum"].ToString(), dr["MachineFeeSum"].ToString(), dr["AreaSum"].ToString(), dr["WeightSum"].ToString());
                    sum1 += Convert.ToDecimal(dr["NumSum"]);
                    sum2 += Convert.ToDecimal(dr["MachineFeeSum"]);
                    sum3 += Convert.ToDecimal(dr["AreaSum"]);
                    sum4 += Convert.ToDecimal(dr["WeightSum"]);
                }
            }
            dt.Rows.Add("总计", sum1, sum2, sum3, sum4);
            GV.DataSource = dt;
            GV.DataBind();
        }

        /// <summary>响应GridView事件：创建数据行时
        /// 	<remark>2010-12-08 BY 河北大学信管团队</remark>
        /// </summary>
        protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //为数据行增加鼠标移动到行特性
                e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;this.style.backgroundColor='" + IMIS_ERP.BLL.Assistant.getColor1 + "'");
                //为数据行增加鼠标离开行特性
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }
}